home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / glibc-1.09 / glibc-1 / glibc-1.09.1 / sysdeps / standalone / m68k / m68020 / mvme136 / console.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-24  |  3.7 KB  |  102 lines

  1. /* Copyright (C) 1994 Free Software Foundation, Inc.
  2.    Contributed by Joel Sherrill (jsherril@redstone-emh2.army.mil),
  3.      On-Line Applications Research Corporation.
  4.  
  5. This file is part of the GNU C Library.
  6.  
  7. The GNU C Library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Library General Public License as
  9. published by the Free Software Foundation; either version 2 of the
  10. License, or (at your option) any later version.
  11.  
  12. The GNU C Library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. Library General Public License for more details.
  16.  
  17. You should have received a copy of the GNU Library General Public
  18. License along with the GNU C Library; see the file COPYING.LIB.  If
  19. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  20. Cambridge, MA 02139, USA.  */
  21.  
  22. #include <ansidecl.h>
  23. #include <standalone.h>
  24. #include "__m68020.h"
  25.  
  26. /* Console IO routines for a Motorola MVME135/MVME136 board.
  27.    
  28. They currently use the B port.  It should be possible to
  29. use the A port by filling in the reset of the chip structure,
  30. adding an ifdef for PORTA/PORTB, and switching the addresses,
  31. and maybe the macroes based on the macro. */
  32.  
  33. /* M68681 DUART chip register structures and constants */
  34.  
  35. typedef struct {
  36.   volatile unsigned char fill1[ 5 ];     /* channel A regs ( not used ) */
  37.   volatile unsigned char isr;            /* interrupt status reg */
  38.   volatile unsigned char fill2[ 2 ];     /* counter regs (not used) */
  39.   volatile unsigned char mr1mr2b;        /* MR1B and MR2B regs */
  40.   volatile unsigned char srb;            /* status reg channel B */
  41.   volatile unsigned char fill3;          /* do not access */
  42.   volatile unsigned char rbb;            /* receive buffer channel B */
  43.   volatile unsigned char ivr;            /* interrupt vector register */
  44. } r_m681_info;
  45.  
  46. typedef struct {
  47.   volatile unsigned char fill1[ 4 ];     /* channel A regs (not used) */
  48.   volatile unsigned char acr;            /* auxillary control reg */
  49.   volatile unsigned char imr;            /* interrupt mask reg */
  50.   volatile unsigned char fill2[ 2 ];     /* counter regs (not used) */
  51.   volatile unsigned char mr1mr2b;        /* MR1B and MR2B regs */
  52.   volatile unsigned char csrb;           /* clock select reg */
  53.   volatile unsigned char crb;            /* command reg */
  54.   volatile unsigned char tbb;            /* transmit buffer channel B */
  55.   volatile unsigned char ivr;            /* interrupt vector register */
  56. } w_m681_info;
  57.  
  58. #define RD_M68681     ((r_m681_info *)0xfffb0040)   /* ptr to the M68681 */
  59. #define WR_M68681     ((w_m681_info *)0xfffb0040)   /* ptr to the M68681 */
  60. #define RXRDYB        0x01               /* status reg recv ready mask */
  61. #define TXRDYB        0x04               /* status reg trans ready mask */
  62.  
  63. /* _Console_Putc
  64.  
  65. This routine transmits a character out the M68681.  It supports
  66. XON/XOFF flow control.  */
  67.  
  68. #define XON             0x11            /* control-Q */
  69. #define XOFF            0x13            /* control-S */
  70.  
  71. int
  72. DEFUN( _Console_Putc, (ch), char ch )
  73. {
  74.   while ( ! (RD_M68681->srb & TXRDYB) ) ;
  75.   while ( RD_M68681->srb & RXRDYB )        /* must be an XOFF */
  76.     if ( RD_M68681->rbb == XOFF ) 
  77.       do {
  78.         while ( ! (RD_M68681->srb & RXRDYB) ) ;
  79.       } while ( RD_M68681->rbb != XON ); 
  80.  
  81.   WR_M68681->tbb = ch;
  82.   return( 0 );
  83. }
  84.  
  85. /* _Console_Getc
  86.  
  87. This routine reads a character from the UART and returns it. */
  88.  
  89. int
  90. DEFUN( _Console_Getc, (poll), int poll )
  91. {
  92.   if ( poll ) {
  93.     if ( !(RD_M68681->srb & RXRDYB) ) 
  94.       return -1;
  95.     else
  96.       return RD_M68681->rbb;
  97.   } else {
  98.     while ( !(RD_M68681->srb & RXRDYB) );
  99.     return RD_M68681->rbb;
  100.   }
  101. }
  102.